
// index.js
// 获取应用实例
const App = getApp();
const HTTP = require('../../utils/util');
const common = require('../../libs/common');
Page({
    data: {
        loading:false,
        location: {},
        swiperList: [],
        shopCateList: [],
        shopCateList2: [],
        shopList: [],
        city: '',
        shopPage: 1,
        shopPageNumber: 10,
        vip_img: '',
        dotsActive: true,
        cate_id: '',



        vertical: false,
        autoplay: true,
        interval: 2000,
        duration: 500,
    },
    onLoad(options) {
        this.setData({
            cate_id: options.id
        })
    },
    //获取二级分类 二级商家
    getClassOne() {
        this.setData({
            loading:true
        });
        HTTP.getData('/api/shop/index', {
            cate_id: this.data.cate_id,
            page: this.data.shopPage,
            limit: this.data.shopPageNumber
        }, res => {
            this.setData({
                vip_img: res.data.vip_image,
                loading:false
            });
            this.handleCateList(res.data.cate);
            common.handlePageChange(this.data.shopPage, res.data.shop.data, this.data.shopList, (e) => {
                this.setData({
                    shopList: e
                });
            }, '商家');
        });
    },
    // 处理分类数组
    handleCateList(res) {
        if (res.length <= 10) {
            this.setData({
                shopCateList: res
            });
        } else {
            let arr1 = res.slice(0, 10);
            let arr2 = res.slice(10)
            this.setData({
                shopCateList: arr1,
                shopCateList2: arr2
            });
        }
    },
    //上拉加载
    onReachBottom(e) {
        this.setData({
            shopPage: this.data.shopPage + 1
        })
        this.getClassOne();
    },
    //监听catelist变化
    listChange(e) {
        if (e.detail.currentItemId === '1') {
            this.setData({
                dotsActive: true
            })
        } else if (e.detail.currentItemId === '2') {
            this.setData({
                dotsActive: false
            })
        }
    },
    onShow() {
        this.setData({
            vip_img:wx.getStorageSync('vip_img')
        });
        this.getClassOne();
    },
    onSearch(e) {
        console.log(e.detail)
    }

})

